package de.tum.in.eist.poll.server;

import java.util.Date;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import de.tum.in.eist.poll.client.Feedback;




public class Database {
	
	
	public static void addFeedbackToLecture(int lectureID, Feedback feedback)
	{
		/* Save feedback using the GAE datastore architecture.
		 * This method gets a unique lecture ID and the new feedback
		 * which is then saved under the unique ID
		 */
		

        Key lectureKey = KeyFactory.createKey("Feedback", Integer.toString(lectureID));
        Date date = new Date();
        Entity feedbackEnt = new Entity("Lecture", lectureKey);
        feedbackEnt.setProperty("feedback", feedback);
        feedbackEnt.setProperty("date", date);

        DatastoreService datastore =
                DatastoreServiceFactory.getDatastoreService();
        datastore.put(feedbackEnt);

	}
}


/*Old version of the database class, as of now saved for safety reasons
 * 
 * 
 * Class Database: As the Google App Engine does not seem to support file writing on the server
 * this "database" uses just the class to save all entries. This happened on advice of our tutor.
 *

public class Database {
	
	int[] answers1;
	String answers2, answers3;
	
	public Database()
	{
		answers1 = new int[5];
		answers2 = answers3 = "";
	}
	
	
	/*
	 * addDataSet: Adds a data set consisting of the answers to all 3 questions to the class attributes.
	 *
	public boolean addDataSet(int answer1, String answer2, String answer3)
	{
		 if(answer1 < 0 || answer1 > 5)
			 return false;
		 
		 answers1[answer1]++;
		 answers2 += answer2 + "\n---------------------------\n";
		 answers3 += answer3 + "\n---------------------------\n";
		 
		 return true;
	}

}*/
 